package org.redswallow.util.config;


import java.io.*;
import java.net.URL;
import java.util.*;

/**
 * $Id: PropertiesFilePropertySet.java,v 1.8 2003/03/27 17:44:23 vanrogu Exp $
 */
public class PropertiesFilePropertySet extends AbstractPropertySet {

    protected Properties props;
    
    public PropertiesFilePropertySet(String path) {
        
    	URL url = getClassLoader().getResource(path);
        
        try {
            props = new Properties();
            props.load(url.openStream());
        } catch (IOException e) {
            props = null;
        }
        
    }

    
    private static ClassLoader getClassLoader() {
    	
    	ClassLoader loader = Thread.currentThread().getContextClassLoader();
    	if (loader == null) {
    		loader = ClassLoader.getSystemClassLoader();
    	}
    	return loader;
    	
    }

    protected String getProperty ( String name ) throws Exception   {
        if ( props == null ) {
            throw new Exception("PropertiesFile not exists!");
        } else{
            return props.getProperty(name);
        }
    }
}
